//
//  SASupplierCell.m
//  saasRetail
//
//  Created by 黄志刚 on 2021/7/2.
//

#import "SASupplierCell.h"
#import "SAProductManufacturerModel.h"

@interface SASupplierCell ()

@property (nonatomic, strong) UIImageView *imageV;
@property (nonatomic, strong) UILabel *nameLab;
@property (nonatomic, strong) UILabel *iphoneLab;
@property (nonatomic, strong) UIImageView *iphoneImage;
@property (nonatomic, strong) UIButton *iphoneBtn;

@end

@implementation SASupplierCell

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    if(self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]){
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        [self initUI];
    }
    return self;
}

-(void)setModel:(SAProductManufacturerModel *)model {
    _model = model;
    _nameLab.text = model.providerName;
    if (model.mobile.length == 0) {
        _iphoneLab.text = @"";
        _iphoneBtn.hidden = YES;
        _iphoneImage.hidden = YES;
    }else {
        _iphoneLab.text = model.mobile;
        _iphoneBtn.hidden = NO;
        _iphoneImage.hidden = NO;
    }
}

-(void)clickedIphoneBtn {
    !self.iphoneBlock ?: self.iphoneBlock(self.model.mobile);
}

-(void)initUI {
    [self.contentView addSubview:self.imageV];
    [self.contentView addSubview:self.nameLab];
    [self.contentView addSubview:self.iphoneLab];
    [self.contentView addSubview:self.iphoneImage];
    [self.contentView addSubview:self.iphoneBtn];
}

-(UIImageView *)imageV {
    if (!_imageV) {
        _imageV = [[UIImageView alloc] initWithFrame:SARectMake(30, 12, 30, 30)];
        _imageV.userInteractionEnabled = YES;
        _imageV.image = [UIImage imageNamed:@"user_headerImage"];
        _imageV.contentMode = UIViewContentModeScaleAspectFit;
    }
    return _imageV;
}

-(UILabel *)nameLab {
    if (!_nameLab) {
        _nameLab = [[UILabel alloc] initWithFrame:SARectMake(66, 0, 110, 55)];
        _nameLab.textColor = kBlackColor;
        _nameLab.font = kFont(15);
    }
    return _nameLab;
}

-(UILabel *)iphoneLab {
    if (!_iphoneLab) {
        _iphoneLab = [[UILabel alloc] initWithFrame:SARectMake(186, 0, 120, 55)];
        _iphoneLab.textColor = kBlackColor;
        _iphoneLab.font = kFont(15);
        _iphoneLab.userInteractionEnabled = NO;
    }
    return _iphoneLab;
}

-(UIImageView *)iphoneImage {
    if (!_iphoneImage) {
        _iphoneImage = [[UIImageView alloc] initWithFrame:SARectMake(kBaseScreenWidth - 58, 18, 19, 19)];
        _iphoneImage.userInteractionEnabled = NO;
        _iphoneImage.image = [UIImage imageNamed:@"red_iphone2"];
        _iphoneImage.contentMode = UIViewContentModeScaleAspectFit;
    }
    return _iphoneImage;
}

-(UIButton *)iphoneBtn {
    if (!_iphoneBtn) {
        _iphoneBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        _iphoneBtn.frame = CGRectMake(kScaleNum(186), 0, kScreenWidth - kScaleNum(186), kScaleNum(50));
        [_iphoneBtn addTarget:self action:@selector(clickedIphoneBtn) forControlEvents:UIControlEventTouchUpInside];
    }
    return _iphoneBtn;
}

@end
